//
//  UIApplication+Ex.swift
//  AIEmoji
//
//  Created by 100Years on 2025/1/22.
//

import UIKit
import AVFoundation
public extension UIApplication {
    // 获取系统音量
    public static func getSystemVolume() -> Float {
        let audioSession = AVAudioSession.sharedInstance()
        do {
            try audioSession.setCategory(.playback) // 设置音频会话为播放模式
            return audioSession.outputVolume
        } catch {
            print("Failed to set audio session category.")
            return -1.0
        }
    }
    

    public enum TSVersionCompareResult {
        case newer
        case older
        case same
    }

    public static func compareAppVersions(newVersion1: String, oldVersion: String) -> TSVersionCompareResult {
        let components1 = newVersion1.components(separatedBy: ".")
        let components2 = oldVersion.components(separatedBy: ".")
        
        let maxLength = max(components1.count, components2.count)
        
        for i in 0..<maxLength {
            let num1 = i < components1.count ? Int(components1[i]) ?? 0 : 0
            let num2 = i < components2.count ? Int(components2[i]) ?? 0 : 0
            
            if num1 > num2 {
                return .newer
            } else if num1 < num2 {
                return .older
            }
        }
        
        return .same
    }
}
